﻿# 指定CMake最低版本
cmake_minimum_required (VERSION 3.12)

# 如果支持，为 MSVC 编译器启用热重载。
if (POLICY CMP0141)
  cmake_policy(SET CMP0141 NEW)
  set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
endif()

# 设置工程名称
project ("kmpWar3")

# 设置可执行文件输出路径
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${PROJECT_SOURCE_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${PROJECT_SOURCE_DIR}/bin")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Zc:wchar_t")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:wchar_t")

# 工程需要管理员权限
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFESTUAC:\"level='requireAdministrator' uiAccess='false'\" /SUBSYSTEM:WINDOWS")

# 增加可执行目标。
add_executable(kmpWar3 WIN32)

# 增加头文件目录
include_directories (third-party/WTL)

# 将当前目录下所有cpp、h文件添加到变量sources中
file(GLOB sources CONFIGURE_DEPENDS *.cpp *.h *.rc)

# 向指定目标增加源代码列表
target_sources(kmpWar3 PUBLIC ${sources})

target_compile_definitions(kmpWar3 PRIVATE UNICODE _UNICODE)
# 增加依赖库
target_link_libraries(kmpWar3 Version)
target_link_libraries(kmpWar3 Psapi)

# 在CMake中启用预编译头文件
target_precompile_headers(kmpWar3 PUBLIC stdafx.h)

# 设置DEBUG模式增加后缀d
set_property(TARGET kmpWar3 PROPERTY DEBUG_POSTFIX d)	

# 关闭release下生成的manifest文件
#set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /MANIFEST:NO")
#set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /MANIFEST:NO")

# 设置c++标准版本
set_property(TARGET kmpWar3 PROPERTY CXX_STANDARD 11)
